home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java 1996 August
/
Java - Summer 1996.iso
/
kaffe-0.2
/
kaffe
/
object.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-02-15
|
3KB
|
161 lines
/*
* object.c
* Handle create and subsequent garbage collection of objects.
*
* Copyright (c) 1996 Systems Architecture Research Centre,
* City University, London, UK.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* Written by Tim Wilkinson <tim@sarc.city.ac.uk>, February 1996.
*/
#include <stdio.h>
#include <assert.h>
#include "gtypes.h"
#include "itypes.h"
#include "object.h"
#include "classMethod.h"
#include "baseClasses.h"
#include "gc.h"
#include "errors.h"
/*
* Primitive object allocation.
*/
inline
object*
newObject(int sz)
{
object* obj;
obj = (object*)calloc(sz, sizeof(char));
if (obj == 0) {
throwException(OutOfMemoryError);
}
return (obj);
}
/*
* Create a new object based on the given class type.
*/
object*
alloc_object(classes* c, bool perm)
{
object* obj;
obj = newObject(sizeof(object) + c->fsize * sizeof(u4));
obj->type = c;
obj->size = c->fsize;
obj->mtable = c->mtable;
obj->final = c->final == true ? 0 : 1;
add_object(obj, perm);
return (obj);
}
/*
* Create a new class object.
*/
classes*
alloc_class(void)
{
classes* obj;
obj = (classes*)newObject(sizeof(classes));
obj->final = 1;
if (ClassClass != 0) {
obj->head.type = ClassClass;
obj->head.mtable = ClassClass->mtable;
obj->head.size = ClassClass->fsize;
}
add_object(&obj->head, true);
return (obj);
}
/*
* Create a new array of data items (not objects).
*/
object*
alloc_array(int sz, int type)
{
object* obj;
int elemsz;
classes* class;
assert(type < MAXTYPES);
assert(TYPE_SIZE(type) != 0);
assert(sz < 100000);
obj = newObject(sizeof(object) + sz*TYPE_SIZE(type));
class = lookupArray(TYPE_ARRAYSIG(type));
obj->type = class;
obj->size = sz;
obj->mtable = class->mtable;
obj->final = 1;
add_object(obj, false);
return (obj);
}
/*
* Create a new array of objects.
*/
object*
alloc_objectarray(int sz, char* csig)
{
char sig[MAXSIG];
object* obj;
classes* class;
assert(sz < 100000);
obj = (object*)newObject(sizeof(object) + sz*sizeof(u4));
/* Build signature for array type */
strcpy(sig, "[");
strcat(sig, csig);
class = lookupArray(addString(sig));
obj->type = class;
obj->size = sz;
obj->mtable = class->mtable;
obj->final = 1;
add_object(obj, false);
return (obj);
}
/*
* Build a multi-dimensional array.
*/
object*
alloc_multiarray(int* dims, char* cname)
{
object* obj;
object** array;
int i;
obj = alloc_objectarray(dims[0], cname+1);
if (dims[1] > 0) {
array = (object**)obj->data;
for (i = 0; i < dims[0]; i++) {
array[i] = alloc_multiarray(dims+1, cname+1);
}
}
add_object(obj, false);
return (obj);
}